package cn.zhentao.dao;

import cn.zhentao.pojo.Address;
import cn.zhentao.pojo.User;
import cn.zhentao.vo.UserVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserDao {
    //登录的方法 根据用户名和密码查所有
    @Select("select * from user where username=#{username} and password=#{password}")
    User findByUserNameAndPassWordUser(@Param("username") String username,@Param("password")String password);
    @Insert("insert into address (name,address_name,add_phone,user_id) values(#{name},#{addressName},#{addPhone},#{userId})")
        //添加地址,并判断,为管理员时添加为门店地址为用户时添加为用户地址
    int addAddress(Address address);
    @Select("select * from address where user_id=#{userId}")
    //根据用户表id查询所有
    List<Address> findAllAddress(int userId);
    @Insert("insert into user(username,password,role_id) values (#{username},#{password},2)")
    int insertUser(User user);
    //查询所有用户信息
    List<UserVo> findAllByRoleId(int userId);
    //修改地址信息
    int updateAddress(Address address);
    //查询地址表根据角色id查询
    List<Address> findAllAddressByUserId();
}
